package edu.student.models;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.util.DB;
/**
Author: Satya Deepthi Bhagi
 **/
public class News {

	private String newsName;
	

	public String getNewsName() {
		return newsName;
	}


	public void setNewsName(String newsName) {
		this.newsName = newsName;
	}


	public static ArrayList<News> getNews(String selectionModifier) {
		ArrayList<News> selection = new ArrayList<News>();
		ResultSet resultSet = null;
		String query = "select news_name from news n,interest i,user_interests ui " + selectionModifier +" and n.interest_id=i.interest_id and i.interest_id= ui.interest_id and n.duration>=sysdate()";
		Connection connection = DB.getConnection();
		resultSet = DB.readFromDB(query, connection);
		try {
			while (resultSet.next()) {
				News newsItem = new News();
				newsItem.newsName=resultSet.getString("NEWS_NAME");
				selection.add(newsItem);	
			}
		} catch (SQLException e) {
	       System.out.println("Exception while reading from db"+ e);
		}
		DB.close(connection);
		return selection;
	}
}
